package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TShipment;
import com.myProject.dao.ShipmentDao;
import com.myProject.serves.ShipmentSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class ShipmentSevImpl implements ShipmentSev {
    @Override
    public List<TShipment> getShipmentList(TShipment tShipment) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ShipmentDao sd = sqlSession.getMapper(ShipmentDao.class);
        sqlSession.clearCache();
        return sd.getShipmentList(tShipment);
    }

    @Override
    public PageInfo<TShipment> showShipmentPage(int pageNo, int pageSize, TShipment tShipment) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ShipmentDao td = sqlSession.getMapper(ShipmentDao.class);
        PageHelper.startPage(pageNo, pageSize);
        List<TShipment> list = td.getShipmentList(tShipment);
        PageInfo<TShipment> page = new PageInfo<TShipment>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }

    @Override
    public boolean addShipment(TShipment tShipment) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ShipmentDao td = sqlSession.getMapper(ShipmentDao.class);
        int x =td.addShipment(tShipment);
        SqlSessionUtil.commit();
        sqlSession.close();
        return x>0?true:false;
    }
}
